﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind2();
            Bind1();
            Bind3();
            Bind4();
        }
    }
    public void Bind1()
    {

        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        string Name = SelectName();
        string sql = "select top 9 title,sid from Email where Meetname='" + Name + "' order by sid desc ";

        SqlDataAdapter da = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        this.DataList2.DataSource = ds;
        this.DataList2.DataBind();
    }
    public string SelectName()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        string sql = "select Name from Employee where username='" + Session["UserName"].ToString() + "'";
        SqlCommand com = new SqlCommand(sql, con);
        SqlDataReader dr = com.ExecuteReader();
        dr.Read();
        string Name = dr.GetValue(0).ToString();
        return Name;

    }
    public int SelectTeacherID(string UserName)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        string sql = "select id from UserInfo where UserName='" + UserName + "'";
        SqlCommand com = new SqlCommand(sql, con);
        SqlDataReader dr = com.ExecuteReader();
        dr.Read();
        int i = Convert.ToInt32(dr["id"].ToString());
        return i;

    }
    public void bind2()
    {
        string UserName = Session["UserName"].ToString();

        int id = SelectTeacherID(UserName);
        //int id = Convert.ToInt32(Request["id"].ToString());
        DataSet ds = new Sqlselete().MyCalendar(id);
        this.DataList1.DataSource = ds.Tables[0];
        this.DataList1.DataBind();

    }
    public void Bind3()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        string sql = "select * from News order by NewsID desc";
        SqlDataAdapter da = new SqlDataAdapter(sql,con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataList3.DataSource = ds;
        DataList3.DataBind();
        con.Close();
    }
    public void Bind4()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        string sql = "select top 9 *  from [Plan] where username='" + Session["UserName"].ToString() + "' order by planid desc";
        SqlDataAdapter da = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        this.DataList4.DataSource = ds;
        this.DataList4.DataBind();

        con.Close();
    }
}
